using System;
using System.Collections.Generic;
using System.Text;

namespace StrategyPattern
{
    abstract class CashSuper
    {
        public abstract double AcceptCash(double money);
    }

    class NormalCash : CashSuper
    {
        public override double AcceptCash(double money)
        {
            return money;
        }
    }

    class DiscountCash : CashSuper
    {
        private double moneyRebate = 1d;
        public DiscountCash(string moneyRebate)
        {
            this.moneyRebate = double.Parse(moneyRebate);
        }
        public override double AcceptCash(double money)
        {
            return money * moneyRebate;
        }
    }

    class RebateCash : CashSuper
    {
        private double moneyCondition = 0.0d;
        private double moneyReturn = 0.0d;
        public RebateCash(string moneyCondition, string moneyReturn)
        {
            this.moneyCondition = double.Parse(moneyCondition);
            this.moneyReturn = double.Parse(moneyReturn);
        }
        public override double AcceptCash(double money)
        {
            double reMoney = money;
            if (money > moneyCondition)
            {
                reMoney = money - Math.Floor(money / moneyCondition) * moneyReturn;
            }

            return reMoney;
        }
    }

    class CashContext
    {
        private CashSuper CashType = null;
        public CashContext(string type,string moneyCondition,string moneyReturn)
        {
            switch (type)
            {
                case "0": 
                    this.CashType = new NormalCash(); break;
                case "1": 
                    this.CashType = new DiscountCash(moneyCondition); break;
                case "2":
                    this.CashType = new RebateCash(moneyCondition, moneyReturn); break;
            }
        }

        public double GetResult(double money)
        {
            return this.CashType.AcceptCash(money);
        }
    }
}
